
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuestIDScreen.java
 *
 * Created on Dec 13, 2011, 8:59:46 PM
 */

/**
 *
 * @author dabeast23
 */
public class CheckOutScreen extends javax.swing.JFrame {

    /** Creates new form GuestIDScreen */
    public CheckOutScreen() {
        setResizable(false);
	setTitle("Hotel Kiosk: Check Out");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        initComponents();
        this.setLocationRelativeTo(null);
        
    }
    
    public CheckOutScreen(ArrayList<Reservation> reservationList, Reservation currentGuest) {
        setResizable(false);
	setTitle("Hotel Kiosk: Check Out");
	setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        this.reservationList = reservationList;
        this.currentGuest = currentGuest;
        initComponents();
        
        this.setLocationRelativeTo(null);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundPanel = new javax.swing.JPanel();
        backButton = new javax.swing.JButton();
        currentTimeLabel = new javax.swing.JLabel();
        checkOutButton = new javax.swing.JButton();
        checkOutLabel1 = new javax.swing.JLabel();
        guestLabel = new javax.swing.JLabel();
        guestNameLabel = new javax.swing.JLabel();
        roomLabel = new javax.swing.JLabel();
        roomNumLabel = new javax.swing.JLabel();
        totalBillLabel = new javax.swing.JLabel();
        totalBillAmountLabel = new javax.swing.JLabel();
        checkOutLabel2 = new javax.swing.JLabel();
        checkOutLabel3 = new javax.swing.JLabel();
        assignedTimeLabel = new javax.swing.JLabel();
        feeLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        backgroundPanel.setBackground(new java.awt.Color(102, 0, 0));
        backgroundPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        backButton.setBackground(new java.awt.Color(255, 255, 204));
        backButton.setFont(new java.awt.Font("Comic Sans MS", 0, 11));
        backButton.setForeground(new java.awt.Color(255, 255, 255));
        backButton.setText("Back");
        backButton.setContentAreaFilled(false);
        backButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backButtonActionPerformed(evt);
            }
        });
        backgroundPanel.add(backButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 260, -1, -1));

        currentTimeLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        currentTimeLabel.setForeground(new java.awt.Color(255, 255, 204));
        currentTimeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        currentTimeLabel.setText("current date and time");
        backgroundPanel.add(currentTimeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 120, -1, 50));
        Calendar calendar = new GregorianCalendar();
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int year = calendar.get(Calendar.YEAR);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        currentTimeLabel.setText(hour+":"+minute+"A.M. on "+ month+"/"+day+"/"+year);

        checkOutButton.setBackground(new java.awt.Color(255, 255, 204));
        checkOutButton.setFont(new java.awt.Font("Comic Sans MS", 0, 18)); // NOI18N
        checkOutButton.setForeground(new java.awt.Color(102, 0, 0));
        checkOutButton.setText("Check Out");
        checkOutButton.setBorder(null);
        checkOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkOutButtonActionPerformed(evt);
            }
        });
        backgroundPanel.add(checkOutButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 250, 171, 33));

        checkOutLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        checkOutLabel1.setForeground(new java.awt.Color(255, 255, 204));
        checkOutLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        checkOutLabel1.setText("Check Out");
        backgroundPanel.add(checkOutLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, -10, 330, 50));

        guestLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        guestLabel.setForeground(new java.awt.Color(255, 255, 204));
        guestLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        guestLabel.setText("Guest:");
        backgroundPanel.add(guestLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 30, -1, 39));

        guestNameLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        guestNameLabel.setForeground(new java.awt.Color(255, 255, 204));
        guestNameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        guestNameLabel.setText("Guest");
        backgroundPanel.add(guestNameLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 30, -1, 39));
        guestNameLabel.setText(currentGuest.getGuestName());

        roomLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        roomLabel.setForeground(new java.awt.Color(255, 255, 204));
        roomLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        roomLabel.setText("Room:");
        backgroundPanel.add(roomLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 60, -1, 39));

        roomNumLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        roomNumLabel.setForeground(new java.awt.Color(255, 255, 204));
        roomNumLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        roomNumLabel.setText("Room");
        backgroundPanel.add(roomNumLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 60, -1, 39));
        roomNumLabel.setText(currentGuest.getRoomNumber().toString());

        totalBillLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        totalBillLabel.setForeground(new java.awt.Color(255, 255, 204));
        totalBillLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        totalBillLabel.setText("Total Bill:");
        backgroundPanel.add(totalBillLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 160, -1, 39));

        totalBillAmountLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        totalBillAmountLabel.setForeground(new java.awt.Color(255, 255, 204));
        totalBillAmountLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        totalBillAmountLabel.setText("Total Bill:");
        backgroundPanel.add(totalBillAmountLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 160, -1, 39));
        double totalBillDouble = (double)Math.round(currentGuest.getTotalBill() * 100) / 100;
        if(currentGuest.getGuestIDNumber().equals("1111"))
        totalBillDouble = totalBillDouble + 25;

        String totalBillString = Double.toString(totalBillDouble);

        totalBillAmountLabel.setText("$"+totalBillString);

        checkOutLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        checkOutLabel2.setForeground(new java.awt.Color(255, 255, 204));
        checkOutLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        checkOutLabel2.setText("Assigned Check Out:");
        backgroundPanel.add(checkOutLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 100, -1, 20));

        checkOutLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        checkOutLabel3.setForeground(new java.awt.Color(255, 255, 204));
        checkOutLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        checkOutLabel3.setText("Actual Check Out:");
        backgroundPanel.add(checkOutLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 120, -1, 50));

        assignedTimeLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        assignedTimeLabel.setForeground(new java.awt.Color(255, 255, 204));
        assignedTimeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        assignedTimeLabel.setText("current date and time");
        backgroundPanel.add(assignedTimeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 90, -1, 40));
        assignedTimeLabel.setText("12:00P.M. on 11/16/2011");
        if(currentGuest.getGuestIDNumber().equals("1111"))
        assignedTimeLabel.setText("11:00A.M. on 11/16/2011");

        feeLabel.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
        feeLabel.setForeground(new java.awt.Color(255, 255, 204));
        feeLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        feeLabel.setText("*A fee of $25 was added to your bill due to your late check out*");
        backgroundPanel.add(feeLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 430, 50));
        feeLabel.setVisible(false);
        if(currentGuest.getGuestIDNumber().equals("1111"))
        feeLabel.setVisible(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        CurrentGuest CG = new CurrentGuest(reservationList,currentGuest);
        CG.setVisible(true);
        this.setVisible(false);
}//GEN-LAST:event_backButtonActionPerformed

    private void checkOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkOutButtonActionPerformed
        // TODO add your handling code here:
        int n = JOptionPane.showConfirmDialog(this,
            "Are you sure you want to check out?\nYour credit card will be charged "+totalBillAmountLabel.getText(),
            "Confirm Check Out", JOptionPane.YES_NO_OPTION);

        if(n==0)
        {
            JOptionPane.showMessageDialog(this,
    "Thank you for your stay!");
            WelcomeScreen WS = new WelcomeScreen(reservationList);
            WS.setVisible(true);
            this.setVisible(false);

        }
    }//GEN-LAST:event_checkOutButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GuestIDScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel assignedTimeLabel;
    private javax.swing.JButton backButton;
    private javax.swing.JPanel backgroundPanel;
    private javax.swing.JButton checkOutButton;
    private javax.swing.JLabel checkOutLabel1;
    private javax.swing.JLabel checkOutLabel2;
    private javax.swing.JLabel checkOutLabel3;
    private javax.swing.JLabel currentTimeLabel;
    private javax.swing.JLabel feeLabel;
    private javax.swing.JLabel guestLabel;
    private javax.swing.JLabel guestNameLabel;
    private javax.swing.JLabel roomLabel;
    private javax.swing.JLabel roomNumLabel;
    private javax.swing.JLabel totalBillAmountLabel;
    private javax.swing.JLabel totalBillLabel;
    // End of variables declaration//GEN-END:variables
    public ArrayList<String> userIDs = new ArrayList();
    private ArrayList <Reservation> reservationList;
    Reservation currentGuest;
   

    
}
